package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolArticleMaterialSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolMaterialArticlePageAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolMaterialArticlePageAdminVO;
import com.sc.nft.service.DaoSchoolArticleMaterialService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 素材表与文章表关联表(DaoSchoolArticleMaterial)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:21:41
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolArticleMaterial")
@Api(tags = "素材表与文章表关联")
public class DaoSchoolArticleMaterialController {

    /**
     * 服务对象
     */
    private final DaoSchoolArticleMaterialService daoSchoolArticleMaterialService;

    @ApiOperation(value = "已选择附件列表", notes = "已选择附件列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolMaterialArticlePageAdminVO> pageAdmin(@RequestBody DaoSchoolMaterialArticlePageAdminDTO pageAdminDTO) {
        return PageResult.success(daoSchoolArticleMaterialService.pageAdmin(pageAdminDTO));
    }


    @ApiOperation(value = "没有被选中的附件列表", notes = "没有被选中的附件列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageNotAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolMaterialArticlePageAdminVO> pageNotAdmin(@RequestBody DaoSchoolMaterialArticlePageAdminDTO pageAdminDTO) {
        return PageResult.success(daoSchoolArticleMaterialService.pageNotAdmin(pageAdminDTO));
    }

    @ApiOperation(value = "删除附件", notes = "删除附件", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Validated IdRequest idRequest) {
        daoSchoolArticleMaterialService.deleteById(idRequest.getId());
        return Result.success();
    }


    @ApiOperation(value = "新增附件", notes = "新增附件", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@RequestBody  List<DaoSchoolArticleMaterialSaveAdminDTO> listInfo) {
        daoSchoolArticleMaterialService.saveAdmin(listInfo);
        return Result.success();
    }

}
